Skip to content

Expose mesh vertex count in SoftBody3D#110331

Open
LordDeatHunter wants to merge 1 commit intogodotengine:masterfrom
LordDeatHunter:expose-existing-softbody-methods
Open

Expose mesh vertex count in SoftBody3D#110331
LordDeatHunter wants to merge 1 commit intogodotengine:masterfrom
LordDeatHunter:expose-existing-softbody-methods

Conversation

@LordDeatHunter
Copy link
Copy Markdown

@LordDeatHunter LordDeatHunter commented Sep 8, 2025

I noticed that a lot of SoftBody3D's functionalities are not exposed in the editor.

With this PR, I exposed the already existing bounding box, as well as creating and exposing a separate method for the vertex (point) count.

With the existing point-related methods, you have to specify an index, but as far as I'm aware, there is no way of knowing if the provided index is valid (in bounds) other than running the game and checking for an error:

Index p_index = 500 is out of bounds ((int)shared->mesh_to_physics.size() = 480).
  <C++ Source>  modules\jolt_physics\objects\jolt_soft_body_3d.cpp:695 @ JoltSoftBody3D::get_vertex_position()

@LordDeatHunter LordDeatHunter requested review from a team as code owners September 8, 2025 20:27
@LordDeatHunter LordDeatHunter force-pushed the expose-existing-softbody-methods branch 2 times, most recently from bcff724 to 74dd435 Compare September 9, 2025 10:56
@AThousandShips AThousandShips added this to the 4.x milestone Sep 9, 2025
@LordDeatHunter LordDeatHunter force-pushed the expose-existing-softbody-methods branch from 74dd435 to 616ec40 Compare October 13, 2025 22:34
@AR-DEV-1 AR-DEV-1 mentioned this pull request Oct 21, 2025
5 tasks
@LordDeatHunter LordDeatHunter force-pushed the expose-existing-softbody-methods branch 2 times, most recently from 565eefc to 81d84ca Compare December 7, 2025 13:01
@Repiteo Repiteo requested a review from a team as a code owner February 17, 2026 20:10
Comment thread modules/jolt_physics/objects/jolt_soft_body_3d.cpp Outdated
Comment thread scene/3d/physics/soft_body_3d.cpp Outdated
@LordDeatHunter LordDeatHunter force-pushed the expose-existing-softbody-methods branch from 81d84ca to 8407b03 Compare February 22, 2026 13:35
Copy link
Copy Markdown
Contributor

@mihe mihe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of notes:

  1. You should ideally make an accompanying proposal when adding new stuff, even if it's just exposing existing data like this, so as to motivate why you need it. You mentioned why you want the point count, but why you need the AABB was less obvious. We need to make sure we're solving whatever root problem you might be having.
  2. PhysicsServer3D.soft_body_get_point_count does not need to be exposed. It will never be any different from the size of the index buffer of the mesh you've assigned to your SoftBody3D. See the discussion in godotengine/godot-proposals#13335 for more details. There might still be some argument for keeping SoftBody3D.get_point_count() though, to simply return a cached value of the index buffer size.
  3. Since SoftBody3D inherits from VisualInstance3D, it already has a virtual get_aabb() method that should be used instead of adding a new get_bounds() method. This could in fact be framed as a bug even, since the editor won't currently show the correct bounds when you select a SoftBody3D using the "3D" input mode in the embedded game view, but will if you implement get_aabb() instead.

(Also, calling the physics server getters directly, like what so many of the methods in SoftBody3D do, is quite problematic for threading reasons as well, but that's beyond the scope of this PR I guess.)

@LordDeatHunter
Copy link
Copy Markdown
Author

LordDeatHunter commented Mar 9, 2026

  1. That's a fair point 👍 I'll keep it in mind for future changes, and we can move the discussion to the existing issue if preferred. Feel free to @ me there.
  2. I only exposed the methods in PhysicsServer3D since I noticed that's how all other SoftBody3D methods are implemented -> by calling existing softbody-related methods from PhysicsServer3D. I don't have any strong opinions on this, so if we agree, I can just implement the same fix from the aforementioned thread directly in SoftBody3D. As for get_point_count, my stance here is still on exposing it in the editor for convenience.
  3. This is an overlook on my part 🤔 Not sure if it wasn't available when I made the PR, or I simply didn't notice it (likely 😅). I'll remove it and rename the PR accordingly.

@LordDeatHunter LordDeatHunter force-pushed the expose-existing-softbody-methods branch from 8407b03 to 700cce1 Compare March 12, 2026 19:07
@LordDeatHunter LordDeatHunter changed the title Expose existing SoftBody3D methods in editor Expose mesh vertex count in SoftBody3D Mar 12, 2026
@LordDeatHunter LordDeatHunter requested review from jrouwe and mihe March 12, 2026 19:09
Copy link
Copy Markdown
Contributor

@jrouwe jrouwe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it is apparently easy to overlook that you can query the mesh for the number of vertices in the soft body, an obvious function that gives you the number seems useful to me.

Comment thread modules/godot_physics_3d/godot_soft_body_3d.cpp Outdated
Comment thread modules/godot_physics_3d/godot_soft_body_3d.h Outdated
Comment thread modules/jolt_physics/objects/jolt_soft_body_3d.cpp Outdated
Comment thread modules/jolt_physics/objects/jolt_soft_body_3d.h Outdated
Comment thread scene/3d/physics/soft_body_3d.cpp
Comment thread scene/3d/physics/soft_body_3d.cpp Outdated
Comment thread scene/3d/physics/soft_body_3d.cpp Outdated
@LordDeatHunter LordDeatHunter force-pushed the expose-existing-softbody-methods branch from 700cce1 to 39ecb08 Compare April 27, 2026 18:30
@LordDeatHunter LordDeatHunter requested a review from mihe April 27, 2026 23:50
@LordDeatHunter LordDeatHunter force-pushed the expose-existing-softbody-methods branch from 39ecb08 to 59b825a Compare April 28, 2026 16:07
Comment thread scene/3d/physics/soft_body_3d.h Outdated
Comment thread scene/3d/physics/soft_body_3d.cpp Outdated
Comment thread scene/3d/physics/soft_body_3d.cpp Outdated
@LordDeatHunter LordDeatHunter force-pushed the expose-existing-softbody-methods branch from 59b825a to 353d960 Compare April 28, 2026 20:51
@LordDeatHunter LordDeatHunter requested a review from mihe April 28, 2026 20:52
Copy link
Copy Markdown
Contributor

@mihe mihe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to work well, and looks good to me.

@mihe mihe modified the milestones: 4.x, 4.8 Apr 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants